package com.hytc.mymall.adapter;

import android.content.Context;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.hytc.mymall.MainActivity;
import com.hytc.mymall.R;
import com.hytc.mymall.base.MyBaseAdapter;
import com.hytc.mymall.bean.HomeInfoBean;
import com.hytc.mymall.utils.BaseTools;

import java.util.List;

public class MainBottomAdapter extends MyBaseAdapter<HomeInfoBean.Home11>
{
    View localView;
    ViewHolder localViewHolder;
    HomeInfoBean.Home11 localHome11;
    List<HomeInfoBean.Home11> data;
    int i;
  public MainBottomAdapter(Context paramContext, List<HomeInfoBean.Home11> paramList)
  {
    super(paramContext, paramList);
      data=paramList;
  }

  public View getView(int paramInt, View paramView, ViewGroup paramViewGroup)
  {
      localHome11=data.get(paramInt);
      Log.e("TAG","data:"+localHome11.remark);
      if(paramView==null){
          localView = View.inflate(this.context, R.layout.layout_item_mainbottom, null);
          localViewHolder = new ViewHolder();
          localViewHolder.rl = ((RelativeLayout)localView.findViewById(R.id.rl_item_mainbottom));
          localViewHolder.iv = ((ImageView)localView.findViewById(R.id.iv_item_mainbottom));
          localView.setTag(localViewHolder);
      }else{
          localViewHolder = (ViewHolder)localView.getTag();
      }
      if (localHome11.remark.equals("ydlm")) {
          i = R.drawable.main_ydlm;
      } else if (localHome11.remark.equals("ydkl")) {
          i = R.drawable.main_ydkl;
      }
      if (localHome11.remark.equals("ydsc")) {
          i = R.drawable.main_ydsc;
      }
      localViewHolder.iv.setImageResource(i);
      if (this.list.size() != 1) {
          RelativeLayout.LayoutParams localLayoutParams1 = new RelativeLayout.LayoutParams(-1, -1);
          localLayoutParams1.setMargins(BaseTools.dip2px(this.context, 20.0F), 0, 0, 0);
          localViewHolder.rl.setLayoutParams(localLayoutParams1);
          localHome11 = this.list.get(paramInt);
          if (this.list.size() == 2) {
              RelativeLayout.LayoutParams localLayoutParams2 = new RelativeLayout.LayoutParams(getWindowsWidth() / 2, -1);
              localViewHolder.rl.setLayoutParams(localLayoutParams2);
          }else {
              RelativeLayout.LayoutParams localLayoutParams3 = new RelativeLayout.LayoutParams(getWindowsWidth() / 3, -1);
              localViewHolder.rl.setLayoutParams(localLayoutParams3);
          }
      }
      return localView;
  }

  public int getWindowsWidth()
  {
    DisplayMetrics localDisplayMetrics = new DisplayMetrics();
    ((MainActivity)this.context).getWindowManager().getDefaultDisplay().getMetrics(localDisplayMetrics);
    return localDisplayMetrics.widthPixels;
  }

  private class ViewHolder
  {
    public ImageView iv;
    public RelativeLayout rl;

    private ViewHolder() {}
  }
}
